home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7049 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: "Double to 2 Unsigned Longs"
  5. Date: 17 Feb 1996 12:30:32 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4g5dt8INNivu@keats.ugrad.cs.ubc.ca>
  8. References: <4g53ml$haj@portal.gmu.edu>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4g53ml$haj@portal.gmu.edu>,
  12. Aires C Domingues <adomingu@osf1.gmu.edu> wrote:
  13.  >How to go about storing a double (used to store very large integers) to
  14.  >a user defined 64 bit integer (structure with two unsigned long fields)?
  15.  >
  16.  >The user defined 64 bit integer looks something like this:
  17.  >
  18.  >typedef struct {
  19.  >  unsigned long high;
  20.  >  unsigned long low;
  21.  >} UINT64;
  22.  >
  23.  >Where "high" is used to save the high order bits for the really big integer,
  24.  >and "low" is used for the low order bits.
  25.  >
  26.  >One idea is to take the double and divide it by 2**32.  The we can save the
  27.  >resulting integral part of the division in "high", and the remainder in the
  28.  >"low".  This will off-course lead to rounding errors.  Any other ideas?
  29.  
  30. It will not lead to round-off errors on architectures that represent
  31. floating-point numbers in binary exponential notation. Multiplying and dividing
  32. by powers of two is equivalent to just adding and subtracting on the floating
  33. point number's exponent; the mantissa bits stay the same.
  34.  
  35. Of course, you would be making a lot of machine-specific assumptions in your
  36. code about the nature of unsigned long numbers, the nature of doubles and their
  37. relationship. Porting your code to different architectures may require
  38. tweaking, so I'd abstract and isolate it as much as possible.
  39. -- 
  40.  
  41.